/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.controller.bean;

import com.entites.EventComment;
import com.entites.EventRegistration;
import com.model.bean.EventCommentFacadeLocal;
import com.model.bean.EventRegistrationFacadeLocal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * @author NguyenVan
 */
@ManagedBean
@SessionScoped
public class EventCommentController {
    @EJB
    private EventCommentFacadeLocal eventCommentFacade;
    
    
    
    /**
     * Creates a new instance of EventCommentController
     */
    public EventCommentController() {
    }
    
 
    private String username;
    private int pages;
    private int currentPages;
    private int noOfRecords;
    private int noOfPage;
    private int eventId;

    FacesContext fCtx = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(true);
    
  
    public int getPages()
    {
        return pages;
    }

    public void setPages(int pages)
    {
        this.pages = pages;
    }

    public int getCurrentPages()
    {
        return currentPages;
    }

    public void setCurrentPages(int currentPages)
    {
        this.currentPages = currentPages;
    }

    public int getNoOfRecords()
    {
        return noOfRecords;
    }

    public void setNoOfRecords(int noOfRecords)
    {
        this.noOfRecords = noOfRecords;
    }

    public int getNoOfPage()
    {
        return noOfPage;
    }

    public void setNoOfPage(int noOfPage)
    {
        this.noOfPage = noOfPage;
    }

    public int getEventId()
    {
        return eventId;
    }

    public void setEventId(int eventId)
    {
        this.eventId = eventId;
    }
    
     public String getUsername() {
        return username = (String) session.getAttribute("username");
    }

    
    public List<EventComment> getListEventComment()
    {
        List<EventComment> lst = new ArrayList<>();
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        if (request.getParameter("pages") != null)
        {
            pages = Integer.parseInt(request.getParameter("pages"));
        }
        int record = 6;
        currentPages = 1;
        if (pages != 0)
        {
            currentPages = pages;
        }
        int start_row = (currentPages * record) - (record - 1);
        int end_row = start_row + record - 1;
        lst = eventCommentFacade.getEventCommentByUser(start_row, end_row, getUsername());
        noOfRecords = eventCommentFacade.count();
        noOfPage = ((int) Math.ceil(noOfRecords * 1.0 / record));
        return lst;
    }
}
